<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="建筑物年代" prop="buildingYear">
        <el-date-picker clearable v-model="queryParams.buildingYear" type="year" placeholder="请选择建筑物年代"
          value-format="yyyy">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="approvalStatus">
        <el-select v-model="queryParams.approvalStatus" placeholder="请选择状态" clearable>
          <el-option v-for="dict in dict.type.approval_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreatedDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['projectManage:projectRemoval:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['projectManage:projectRemoval:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['projectManage:projectRemoval:remove']">批量删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['projectManage:projectRemoval:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" style="width: 100%" :data="projectRemovalList"
      @selection-change="handleSelectionChange">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="征收实施单位">
              <span>{{ props.row.constructionDept }}</span>
            </el-form-item>
            <el-form-item label="征收实施单位联系人">
              <span>{{ props.row.constructionPerson }}</span>
            </el-form-item>
            <el-form-item label="征收实施单位联系电话">
              <span>{{ props.row.constructionPhone }}</span>
            </el-form-item>
            <el-form-item label="拆除单位">
              <span>{{ props.row.removalDept }}</span>
            </el-form-item>
            <el-form-item label="拆除单位联系人">
              <span>{{ props.row.removalPerson }}</span>
            </el-form-item>
            <el-form-item label="拆除单位联系方式">
              <span>{{ props.row.removalPhone }}</span>
            </el-form-item>
            <el-form-item label="资源化利用企业">
              <span>{{ props.row.disposalLandName }}</span>
            </el-form-item>
            <el-form-item label="资源化利用企业联系人">
              <span>{{ props.row.disposalLandPerson }}</span>
            </el-form-item>
            <el-form-item label="资源化利用企业联系电话">
              <span>{{ props.row.disposalLandPhone }}</span>
            </el-form-item>
            <el-form-item label="运输单位">
              <span>{{ props.row.transportCompanyName }}</span>
            </el-form-item>
            <el-form-item label="审批意见">
              <span>{{ props.row.approvalDesc }}</span>
            </el-form-item>
            <el-form-item label="运输单位联系人">
              <span>{{ props.row.transportCompanyPerson }}</span>
            </el-form-item>
            <el-form-item label="运输单位联系电话">
              <span>{{ props.row.transportCompanyPhone }}</span>
            </el-form-item>
            <el-form-item label="运输单位车辆信息">
              <span>{{ props.row.transportCompanyCarInfo }}</span>
            </el-form-item>
            <el-form-item label="预计拆除面积(m²)">
              <span>{{ props.row.rubbishRemovalArea }}</span>
            </el-form-item>
            <el-form-item label="其中住宅面积(m²)">
              <span>{{ props.row.rubbishHouseArea }}</span>
            </el-form-item>
            <el-form-item label="预计垃圾重量(吨)">
              <span>{{ props.row.rubbishPlanWeight }}</span>
            </el-form-item>
            <el-form-item label="可利用重量(吨)">
              <span>{{ props.row.rubbishRecycleWeight }}</span>
            </el-form-item>
            <el-form-item label="可利用比例(%)">
              <span>{{ props.row.rubbishRecycleRatio }}</span>
            </el-form-item>
            <el-form-item label="预计清运时间">
              <span>{{ parseTime(props.row.rubbishPlanTransportDate, '{y}-{m}-{d}') }}</span>
            </el-form-item>
            <el-form-item label="垃圾分拣拆除计划">
              <span>
                <dict-tag :options="dict.type.stage_fill" :value="props.row.classifyStage" />
              </span>
            </el-form-item>
            <el-form-item label="建筑垃圾资源化利用计划">
              <span>
                <dict-tag :options="dict.type.stage_fill" :value="props.row.recycleStage" />
              </span>
            </el-form-item>
            <el-form-item label="审批意见">
              <span>{{ props.row.approvalDesc }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" width="200" show-overflow-tooltip />
      <el-table-column label="项目类型" align="center" prop="projectKindId" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_kind_id" :value="scope.row.projectKindId" />
        </template>
      </el-table-column>
      <el-table-column label="项目地址" align="center" prop="projectAddress" width="100" show-overflow-tooltip />
      <el-table-column label="状态" align="center" prop="approvalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.approval_status" :value="scope.row.approvalStatus" />
        </template>
      </el-table-column>
      <el-table-column label="建筑物年代" align="center" prop="buildingYear" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.buildingYear }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结构类型" align="center" prop="structureType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.structure_type_id" :value="scope.row.structureType" />
        </template>
      </el-table-column>
      <el-table-column label="拆除工期" align="center" prop="removalPeriod" width="180" />
      <el-table-column label="曾经用途" align="center" prop="buildingUse" width="100" show-overflow-tooltip />
      <el-table-column label="审批时间" align="center" prop="approvalDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvalDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createdDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"
            v-hasPermi="['projectManage:projectRemoval:query']">查看</el-button>
          <el-button size="mini" type="text" v-if="scope.row.approvalStatus == 20" @click="handleApprove(scope.row)"
            v-hasPermi="['projectManage:projectRemoval:approve']">审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
      @pagination="getList" />

    <!-- 添加或修改拆迁备案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目ID" />
        </el-form-item>
        <el-form-item label="建筑物年代" prop="buildingYear">
          <el-date-picker clearable v-model="form.buildingYear" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择建筑物年代">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结构类型" prop="structureType">
          <el-select v-model="form.structureType" placeholder="请选择结构类型">
            <el-option v-for="dict in dict.type.structure_type_id" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="拆除工期" prop="removalPeriod">
          <el-input v-model="form.removalPeriod" placeholder="请输入拆除工期" />
        </el-form-item>
        <el-form-item label="曾经用途" prop="buildingUse">
          <el-input v-model="form.buildingUse" placeholder="请输入曾经用途" />
        </el-form-item>
        <el-form-item label="征收实施单位" prop="constructionDept">
          <el-input v-model="form.constructionDept" placeholder="请输入征收实施单位" />
        </el-form-item>
        <el-form-item label="征收实施单位联系人" prop="constructionPerson">
          <el-input v-model="form.constructionPerson" placeholder="请输入征收实施单位联系人" />
        </el-form-item>
        <el-form-item label="征收实施单位联系电话" prop="constructionPhone">
          <el-input v-model="form.constructionPhone" placeholder="请输入征收实施单位联系电话" />
        </el-form-item>
        <el-form-item label="拆除单位" prop="removalDept">
          <el-input v-model="form.removalDept" placeholder="请输入拆除单位" />
        </el-form-item>
        <el-form-item label="拆除单位联系人" prop="removalPerson">
          <el-input v-model="form.removalPerson" placeholder="请输入拆除单位联系人" />
        </el-form-item>
        <el-form-item label="拆除单位联系方式" prop="removalPhone">
          <el-input v-model="form.removalPhone" placeholder="请输入拆除单位联系方式" />
        </el-form-item>
        <el-form-item label="资源化利用企业" prop="disposalLandId">
          <el-input v-model="form.disposalLandId" placeholder="请输入资源化利用企业" />
        </el-form-item>
        <el-form-item label="资源化利用企业联系人" prop="disposalLandPerson">
          <el-input v-model="form.disposalLandPerson" placeholder="请输入资源化利用企业联系人" />
        </el-form-item>
        <el-form-item label="资源化利用企业联系电话" prop="disposalLandPhone">
          <el-input v-model="form.disposalLandPhone" placeholder="请输入资源化利用企业联系电话" />
        </el-form-item>
        <el-form-item label="运输单位" prop="transportCompanyId">
          <el-input v-model="form.transportCompanyId" placeholder="请输入运输单位" />
        </el-form-item>
        <el-form-item label="运输单位联系人" prop="transportCompanyPerson">
          <el-input v-model="form.transportCompanyPerson" placeholder="请输入运输单位联系人" />
        </el-form-item>
        <el-form-item label="运输单位联系电话" prop="transportCompanyPhone">
          <el-input v-model="form.transportCompanyPhone" placeholder="请输入运输单位联系电话" />
        </el-form-item>
        <el-form-item label="运输单位意见" prop="transportCompanySuggestion">
          <el-input v-model="form.transportCompanySuggestion" placeholder="请输入运输单位意见" />
        </el-form-item>
        <el-form-item label="运输单位车辆信息" prop="transportCompanyCarInfo">
          <el-input v-model="form.transportCompanyCarInfo" placeholder="请输入运输单位车辆信息" />
        </el-form-item>
        <el-form-item label="预计拆除面积(m²)" prop="rubbishRemovalArea">
          <el-input v-model="form.rubbishRemovalArea" placeholder="请输入预计拆除面积" />
        </el-form-item>
        <el-form-item label="其中住宅面积(m²)" prop="rubbishHouseArea">
          <el-input v-model="form.rubbishHouseArea" placeholder="请输入其中住宅面积" />
        </el-form-item>
        <el-form-item label="预计产生垃圾(吨)" prop="rubbishPlanWeight">
          <el-input v-model="form.rubbishPlanWeight" placeholder="请输入预计垃圾重量" />
        </el-form-item>
        <el-form-item label="预计可利用(吨)" prop="rubbishRecycleWeight">
          <el-input v-model="form.rubbishRecycleWeight" placeholder="请输入可利用重量" />
        </el-form-item>
        <el-form-item label="可利用比例(%)" prop="rubbishRecycleRatio">
          <el-input v-model="form.rubbishRecycleRatio" placeholder="请输入可利用比例" />
        </el-form-item>
        <el-form-item label="预计清运时间" prop="rubbishPlanTransportDate">
          <el-date-picker clearable v-model="form.rubbishPlanTransportDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择预计清运时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="垃圾分拣拆除计划" prop="classifyStage">
          <el-input v-model="form.classifyStage" placeholder="请输入垃圾分拣拆除计划" />
        </el-form-item>
        <el-form-item label="建筑垃圾资源化利用计划" prop="recycleStage">
          <el-input v-model="form.recycleStage" placeholder="请输入建筑垃圾资源化利用计划" />
        </el-form-item>
        <el-form-item label="图片">
          <image-upload v-model="form.projectImages" />
        </el-form-item>
        <el-form-item label="状态" prop="approvalStatus">
          <el-select v-model="form.approvalStatus" placeholder="请选择状态( 10:未提交,20:待审核;30:已通过;40:未通过)">
            <el-option v-for="dict in dict.type.approval_status" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审批意见" prop="approvalDesc">
          <el-input v-model="form.approvalDesc" placeholder="请输入审批意见" />
        </el-form-item>
        <el-form-item label="审批时间" prop="approvalDate">
          <el-date-picker clearable v-model="form.approvalDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="createdDate">
          <el-date-picker clearable v-model="form.createdDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="modifiedDate">
          <el-date-picker clearable v-model="form.modifiedDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择修改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--详情-->
    <project-removal-detail :visible.sync="detailOpen" :title="title" :readonly="readonly" :formData="form"
      @commit="sumitApprove" />
  </div>
</template>

<script>
import { listProjectRemoval, getProjectRemoval, delProjectRemoval, addProjectRemoval, updateProjectRemoval, approve } from "@/api/projectManage/projectRemoval";
import ProjectRemovalDetail from "@/views/projectManage/projectRemoval/projectRemovalDetail";

export default {
  name: "ProjectRemoval",
  dicts: ['approval_status', 'structure_type_id', 'project_kind_id', 'stage_fill'],
  components: { ProjectRemovalDetail },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 拆迁备案表格数据
      projectRemovalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 修改时间时间范围
      daterangeCreatedDate: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        projectId: null,
        buildingYear: null,
        structureType: null,
        removalPeriod: null,
        buildingUse: null,
        constructionDept: null,
        constructionPerson: null,
        constructionPhone: null,
        removalDept: null,
        removalPerson: null,
        removalPhone: null,
        disposalLandId: null,
        disposalLandPerson: null,
        disposalLandPhone: null,
        transportCompanyId: null,
        transportCompanyPerson: null,
        transportCompanyPhone: null,
        transportCompanySuggestion: null,
        transportCompanyCarInfo: null,
        rubbishRemovalArea: null,
        rubbishHouseArea: null,
        rubbishPlanWeight: null,
        rubbishRecycleWeight: null,
        rubbishRecycleRatio: null,
        rubbishPlanTransportDate: null,
        classifyStage: null,
        recycleStage: null,
        projectImages: null,
        approvalStatus: null,
        approvalDesc: null,
        approvalDate: null,
        createdDate: null,
        projectName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectId: [
          { required: true, message: "项目ID不能为空", trigger: "blur" }
        ],
      },
      detailOpen: false,
      readonly: true
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询拆迁备案列表 */
    getList () {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreatedDate && '' != this.daterangeCreatedDate) {
        this.queryParams.params["beginCreatedDate"] = this.daterangeCreatedDate[0];
        this.queryParams.params["endCreatedDate"] = this.daterangeCreatedDate[1];
      }
      listProjectRemoval(this.queryParams).then(response => {
        this.projectRemovalList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        projectId: null,
        buildingYear: null,
        buildingType: null,
        structureType: null,
        removalPeriod: null,
        buildingUse: null,
        constructionDept: null,
        constructionPerson: null,
        constructionPhone: null,
        removalDept: null,
        removalPerson: null,
        removalPhone: null,
        disposalLandId: null,
        disposalLandPerson: null,
        disposalLandPhone: null,
        transportCompanyId: null,
        transportCompanyPerson: null,
        transportCompanyPhone: null,
        transportCompanySuggestion: null,
        transportCompanyCarInfo: null,
        rubbishRemovalArea: null,
        rubbishHouseArea: null,
        rubbishPlanWeight: null,
        rubbishRecycleWeight: null,
        rubbishRecycleRatio: null,
        rubbishPlanTransportDate: null,
        classifyStage: null,
        recycleStage: null,
        projectImages: null,
        approvalStatus: null,
        approvalDesc: null,
        approvalDate: null,
        createdDate: null,
        modifiedDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreatedDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加拆迁备案";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      getProjectRemoval(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改拆迁备案";
      });
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProjectRemoval(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjectRemoval(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除选中的数据项？').then(function () {
        return delProjectRemoval(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('projectManage/projectRemoval/export', {
        ...this.queryParams
      }, `拆迁备案_${new Date().getTime()}.xlsx`)
    },
    // 提交审核
    sumitApprove (data) {
      approve(data).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 详情
    handleDetail (row) {
      this.reset();
      getProjectRemoval(row.id).then(response => {
        this.form = response.data;
        this.detailOpen = true;
        this.title = "拆迁备案详情";
        this.readonly = true;
      });
    },
    // 审批
    handleApprove (row) {
      this.reset();
      getProjectRemoval(row.id).then(response => {
        this.form = response.data;
        this.detailOpen = true;
        this.title = "拆迁备案审批";
        this.readonly = false;
      });
    }
  }
};
</script>
<style scoped>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>